import os

from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from django.utils import simplejson


class MainPage(webapp.RequestHandler):
    def get(self):
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, None))
          
        
        
class Spam(webapp.RequestHandler):
    def post(self):
        
        
        origin = self.request.get('origin')
        origin_coords = self.request.get('origin_coords')
        destination = self.request.get('destination')
        destination_coords = self.request.get('destination_coords')
        memcache.add('destination_coords',destination_coords,60)
        self.response.out.write(simplejson.dumps({"origin":origin,"destination":destination}, sort_keys=True))
        
    def get(self):
        print memcache.get('destination_coords')

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/teste', Spam)], #change this to a proper name.                                  
                                     debug=False
                                     )
def main():
    run_wsgi_app(application)
if __name__ == "__main__":
    main() 